//
//  QSImagePickerController.m
//  TestTouchEvent
//
//  Created by apple on 2016/11/17.
//  Copyright © 2016年 MGCoin. All rights reserved.
//

#import "QSImagePickerController.h"

@interface QSImagePickerController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@end

@implementation QSImagePickerController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.allowsEditing = YES;
    self.delegate = self;
    self.view.backgroundColor = [UIColor colorWithWhite:0.875 alpha:1.000];
}

/**
 *  选取照片
 */
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    //界面返回
    [picker dismissViewControllerAnimated:YES completion:nil];
    //获取编辑之后的图片
    UIImage *editedImage=[info objectForKey:UIImagePickerControllerEditedImage];
    //将获取的image传入代理方法中
    if ([self.QSDelegate respondsToSelector:@selector(imageChooseFinish:)]) {
        [self.QSDelegate imageChooseFinish:editedImage];
    }
}

#pragma mark - Setter
- (void)setNavBarColor:(UIColor *)navBarColor
{
    _navBarColor = navBarColor;
    
    [self.navigationBar setBarTintColor:navBarColor];
}

- (void)setNavBarBgImage:(UIImage *)navBarBgImage
{
    _navBarBgImage = navBarBgImage;
    
    [self.navigationBar setBackgroundImage:navBarBgImage forBarMetrics:UIBarMetricsDefault];
}

- (void)setNavTitleColor:(UIColor *)navTitleColor
{
    _navTitleColor = navTitleColor;
    
    NSMutableDictionary *textAttDict = [self.navigationBar.titleTextAttributes mutableCopy];
    if (!textAttDict) {
        textAttDict = [NSMutableDictionary dictionary];
    }
    [textAttDict setValue:navTitleColor forKey:NSForegroundColorAttributeName];
    [self.navigationBar setTitleTextAttributes:textAttDict];
}

- (void)setNavTitleFont:(UIFont *)navTitleFont
{
    _navTitleFont = navTitleFont;
    
    NSMutableDictionary *textAttDict = [self.navigationBar.titleTextAttributes mutableCopy];
    if (!textAttDict) {
        textAttDict = [NSMutableDictionary dictionary];
    }
    [textAttDict setValue:navTitleFont forKey:NSFontAttributeName];
    [self.navigationBar setTitleTextAttributes:textAttDict];
}

- (void)setNavBtnColor:(UIColor *)navBtnColor
{
    _navBtnColor = navBtnColor;
    
    [self.navigationBar setTintColor:navBtnColor];
}

- (void)setImgPickerStyle:(ImagePickerStyle)imgPickerStyle
{
    _imgPickerStyle = imgPickerStyle;
    
    if (imgPickerStyle == ImagePickerStyleCamera) {
        self.sourceType = UIImagePickerControllerSourceTypeCamera;
    }else if(imgPickerStyle == ImagePickerStylePhotoLibrary){
        self.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
}
@end
